Windows Phone 8 Development Internals by Andrew Whitechapel & Sean McKenna

Windows Phone 8 Development Internals by Andrew Whitechapel & Sean McKenna

Author:Andrew Whitechapel & Sean McKenna [Andrew Whitechapel and Sean McKenna]
Language: eng
Format: epub
Tags: COMPUTERS / Programming / Microsoft Programming
ISBN: 9780735676206
Publisher: Microsoft Press
Published: 2012-10-28T16:00:00+00:00


Note

If you want to generate images on the fly, and you want to include transparency, you need to save your images in PNG format. However, this is not supported in the standard library. A solution that you can consider is the WriteableBitmapEx third-party library, which is available on codeplex at http://writeablebitmapex.codeplex.com/.

In this sample app, Page2 also has a TextBlock whose Text is set to a string that indicates whether the user navigated to this page via a pinned tile on the Start screen or via the HyperlinkButton on the MainPage. When you create a secondary tile, you can also specify the NavigationUri for the tile. This must include the page to which to navigate within this app, plus, optionally, a query string with whatever parameters you want. This sample app sets one ID parameter, which it uses subsequently to determine which tile this is. When you call the ShellTile.Create method, the tile is created with the specified properties and pinned to the Start screen on the phone. The Start screen is an app that is part of the system shell, so this action causes a navigation away from your app, which is therefore deactivated. The reason for this is to avoid spamming the Start screen: when you create a tile, the system makes it very obvious to the user that the tile has been created, and the user is shown where the tile is. She can then immediately interact with it, perhaps by moving it around, resizing it, or deleting it if she doesn’t want it.

There are two ways to get to Page2 in the app: through normal navigation via the hyperlink on the main page of the app, or via a pinned tile on the Start screen. So that you can determine which route was taken, you need to override the OnNavigatedTo method. This is where the ID parameter comes into play; the app can examine the query string to see which tile the user tapped to get to this page. This is also where you cache the ShellTile object. There’s only one secondary tile in this app, so you can cache this as a ShellTile field in the class. If there were more tiles, it would make sense to use a collection, instead.

protected override void OnNavigatedTo(NavigationEventArgs e) { String tmp; if (NavigationContext.QueryString.TryGetValue("ID", out tmp)) { navigation.Text = String.Format("from Start ({0})", tmp); } else { navigation.Text = "from MainPage link"; } tile = ShellTile.ActiveTiles.FirstOrDefault( x => x.NavigationUri.ToString().Contains("ID=" +tmp)); }

In this example, if the query string indicates that the user arrived at Page2 via a pinned tile, you simply extract the parameter value and display it in a TextBlock. In a more sophisticated app, you would use this identifier to govern some business logic in your solution.

Updating a tile’s properties and deleting a tile are both very straightforward. To update a tile, you simply find that tile and invoke the Update method, passing in a replacement set of data by using an object of the appropriate ShellTileData-derived class (FlipTileData, CycleTileData, or IconicTileData), as before.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.